package cn.edu.hqu.cst.android.ljc.test2;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import java.util.Timer;
import java.util.TimerTask;

public class uc3 extends AppCompatActivity {
    ImageView imageView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_uc3);
        imageView = findViewById(R.id.imageView);
        //使用定时器
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                handler.sendEmptyMessage(1);
            }
        },0,400);

        //返回
        Button uc3_bt1 = findViewById(R.id.uc3_bt1);
        uc3_bt1 .setOnClickListener(view -> finish());
    }

    //图片数组
    int[] imgIds = new int[]{R.drawable.pic1,R.drawable.pic2,R.drawable.pic3,
            R.drawable.pic4,R.drawable.pic5,};
    int start = 0;

    Handler handler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            if (msg.what == 1){
                imageView.setImageResource(imgIds[start++ % 5]);
            }
        }
    };

}